﻿<%@ Page Language="C#" MasterPageFile="~/Base.Master" AutoEventWireup="true" CodeBehind="Accountants.aspx.cs" Inherits="SVAccountingWebUI.Accountants" %>
<%@ MasterType VirtualPath="~/Base.Master" %>

<asp:Content ID="AccountantsContent" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" BackColor="White" 
        BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" 
        DataKeyNames="AccountantID" DataSourceID="LinqDataSource" ForeColor="Black" 
        GridLines="Vertical"
        onrowcancelingedit="gv_RowCancelingEdit" 
        onrowdeleting="gv_RowDeleting" onrowediting="gv_RowEditing"
        >
        <Columns>
            <asp:TemplateField HeaderText="<%$ Resources:Resource, EditDelete %>">
                <EditItemTemplate>
                &nbsp;
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" ImageUrl="~/Icons/Update.png" Text="Update" />
                    /&nbsp;<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" ImageUrl="~/Icons/Cancel.png" Text="Cancel" />
                </EditItemTemplate>
                <ItemTemplate>
                &nbsp;
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" ImageUrl="~/Icons/Edit.png" Text="Edit" />
                   /&nbsp;<asp:ImageButton ID="DeleteButton" runat="server" CausesValidation="False" 
                        CommandName="Delete" ImageUrl="~/Icons/delete.png" Text="Delete"
                        message="<%$ Resources:Resource, DeleteConfirm %>" 
                        OnClientClick='return confirm(this.getAttribute("message"))'
                        />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="AccountantID" HeaderText="<%$ Resources:Resource, ID %>" 
                InsertVisible="False" ReadOnly="True" SortExpression="AccountantID" />
            <asp:TemplateField HeaderText="<%$ Resources:Resource, User %>" SortExpression="PersonID">
                <EditItemTemplate>
                    <%--<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PersonID") %>'></asp:TextBox>--%>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Person.FirstName") %>'></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Person.FirstName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$ Resources:Resource, Company %>" SortExpression="CompanyID">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" 
                        DataSourceID="CompaniesLinqDataSource" DataTextField="CompanyName" 
                        DataValueField="CompanyID" SelectedValue='<%# Bind("CompanyID") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Company.CompanyName") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$ Resources:Resource, StartDate %>" SortExpression="StartDate">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("StartDate") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$ Resources:Resource, EndDate %>" SortExpression="EndDate">
                <EditItemTemplate>
                    <asp:TextBox ID="txtEndDate" runat="server" />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("EndDate") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <FooterStyle BackColor="#CCCCCC" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="#CCCCCC" />
    </asp:GridView>
    
    <asp:LinqDataSource ID="LinqDataSource" runat="server" 
        ContextTypeName="SVAccountingBL.SVALinqDataContext" EnableDelete="True" 
        EnableInsert="True" EnableUpdate="True" TableName="rAccountantPersons"
        ondeleted="LinqDataSource_Deleted" 
        onupdated="LinqDataSource_Updated" 
        oninserted="LinqDataSource_Inserted" 
        oninserting="LinqDataSource_Inserting"
        />
    
    
     <asp:LinqDataSource ID="CompaniesLinqDataSource" runat="server" 
                        ContextTypeName="SVAccountingBL.SVALinqDataContext" 
                        Select="new (CompanyID, CompanyName)" TableName="Companies">
    </asp:LinqDataSource>
    
    <asp:LinqDataSource ID="PersonsLinqDataSource" runat="server" 
                           ContextTypeName="SVAccountingBL.SVALinqDataContext" 
                           Select="new (PersonID, FirstName)" TableName="Persons">
    </asp:LinqDataSource>


<asp:UpdatePanel ID="AddNewPanel" runat="server">
   <ContentTemplate>
    <br />
    <asp:LinkButton ID="lbtnAddNew" runat="server" 
                    Text="<%$ Resources:Resource, AddNew %>" 
           onclick="AddNew_Click"/>
    <br />
    <br />
   <div ID="InsertDiv" runat="server" visible="false">
       <asp:DetailsView ID="dvNewAccountant" runat="server" Height="50px" Width="125px" 
           AutoGenerateRows="False" CellPadding="4" DataKeyNames="AccountantID" 
           DataSourceID="LinqDataSource" DefaultMode="Insert" ForeColor="#333333" 
           GridLines="None"  onitemcommand="InsertDV_ItemCommand">
           <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
           <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
           <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
           <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
           <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
           <Fields>
               <asp:BoundField DataField="AccountantID" HeaderText="AccountantID" 
                   InsertVisible="False" ReadOnly="True" SortExpression="AccountantID" />
               <asp:TemplateField HeaderText="<%$ Resources:Resource, User %>" SortExpression="PersonID">
                   <EditItemTemplate>
                       <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("PersonID") %>'></asp:TextBox>
                   </EditItemTemplate>
                   <InsertItemTemplate>
                       <asp:DropDownList ID="DropDownList2" runat="server" 
                           DataSourceID="PersonsLinqDataSource" DataTextField="FirstName" 
                           DataValueField="PersonID" SelectedValue='<%# Bind("PersonID") %>'>
                       </asp:DropDownList>
                   </InsertItemTemplate>
                   <ItemTemplate>
                       <asp:Label ID="Label4" runat="server" Text='<%# Bind("PersonID") %>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="<%$ Resources:Resource, Company %>" SortExpression="CompanyID">
                   <EditItemTemplate>
                       <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("CompanyID") %>'></asp:TextBox>
                   </EditItemTemplate>
                   <InsertItemTemplate>
                       <asp:DropDownList ID="DropDownList3" runat="server" 
                           DataSourceID="CompaniesLinqDataSource" DataTextField="CompanyName" 
                           DataValueField="CompanyID" SelectedValue='<%# Bind("CompanyID") %>'>
                       </asp:DropDownList>
                   </InsertItemTemplate>
                   <ItemTemplate>
                       <asp:Label ID="Label3" runat="server" Text='<%# Bind("CompanyID") %>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="<%$ Resources:Resource, StartDate %>" SortExpression="StartDate">
                   <EditItemTemplate>
                       <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("StartDate") %>'></asp:TextBox>
                   </EditItemTemplate>
                   <InsertItemTemplate>
                       <asp:Calendar ID="Calendar3" runat="server" BackColor="White" 
                           BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" 
                           Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" 
                           SelectedDate='<%# Bind("StartDate") %>' Width="200px">
                           <SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
                           <SelectorStyle BackColor="#CCCCCC" />
                           <WeekendDayStyle BackColor="#FFFFCC" />
                           <TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
                           <OtherMonthDayStyle ForeColor="#808080" />
                           <NextPrevStyle VerticalAlign="Bottom" />
                           <DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
                           <TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
                       </asp:Calendar>
                   </InsertItemTemplate>
                   <ItemTemplate>
                       <asp:Label ID="Label2" runat="server" Text='<%# Bind("StartDate") %>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="<%$ Resources:Resource, EndDate %>" SortExpression="EndDate">
                   <EditItemTemplate>
                       <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("EndDate") %>'></asp:TextBox>
                   </EditItemTemplate>
                   <InsertItemTemplate>
                       <asp:Calendar ID="Calendar4" runat="server" 
                           SelectedDate='<%# Bind("EndDate") %>'></asp:Calendar>
                   </InsertItemTemplate>
                   <ItemTemplate>
                       <asp:Label ID="Label1" runat="server" Text='<%# Bind("EndDate") %>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>
               <asp:CommandField ButtonType="Image" CancelImageUrl="~/Icons/Cancel.png" 
                   InsertImageUrl="~/Icons/Add.png" ShowInsertButton="True" />
           </Fields>
           <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
           <EditRowStyle BackColor="#999999" />
           <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
       </asp:DetailsView>
    </div>
    </ContentTemplate>
    
    <Triggers>
         <asp:AsyncPostBackTrigger ControlID="lbtnAddNew" EventName="click" />
         <asp:PostBackTrigger ControlID="dvNewAccountant" /> 
    </Triggers>
    
   </asp:UpdatePanel>

</asp:Content> 